package com.xuyuan.agent.util;

import com.xuyuan.agent.cglib.CglibProxy;
import com.xuyuan.agent.jdk.JDKProxyDynamic;
import org.springframework.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public class ProxyUtil {

    /**
     * 获取CGLIB动态代理类
     */
    public static Object getCglibProxyObject(Class target) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(target);
        enhancer.setCallback(CglibProxy.getInstance());
        return enhancer.create();
    }

    /**
     * 获取JDK动态代理对象
     */
    public static Object getJDKProxyObject(Class target) {
        JDKProxyDynamic jdkProxyDynamic = new JDKProxyDynamic(target);
        return Proxy.newProxyInstance(target.getClassLoader(), target.getInterfaces(), jdkProxyDynamic);
    }

}
